﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FShop_BAL;
using FShop_DAL;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session.RemoveAll();
        txtUsername.Focus();
    }
    protected void ImageButtonLogin_Click(object sender, ImageClickEventArgs e)
    {
        //Session["User_Type"] = 2;
        //Session["User_ID"] = 1;
        //Response.Redirect("ad/ManageProduct.aspx");

        string mem_ID = string.Empty;
        if (! User_BAL.IsExitUser(txtUsername.Text.Trim(), CryptorEngine.Encrypt(txtPassword.Text.Trim(), true), ref mem_ID))
        {
            lblError.Text = "Tên đăng nhập hoặc mật khẩu không đúng.";
        }
        else
        {
            FShop_DAL.User mem = User_BAL.Get_User_ByID(int.Parse(mem_ID));
            if (mem != null)
            {
                Session["User_Type"] = mem.User_Type;
                Session["User_ID"] = mem.User_ID;

                if (mem.User_Type == 0)
                    Response.Redirect("Default.aspx");
                else
                    if (mem.User_Type == 1)
                        Response.Redirect("ad/Default.aspx");
                    else
                        if (mem.User_Type == 2)
                            Response.Redirect("ad/ManageNews.aspx");
            }
        }
    }
}
